﻿using Microsoft.Data.SqlClient;
using System.Data;

namespace Dz.WorkerService.Utils
{
    internal class TaxScheduleUtils : BaseUtils
    {
        private Dictionary<string,string> taxs = new Dictionary<string, string>();
        private static readonly Lazy<TaxScheduleUtils> instance = new Lazy<TaxScheduleUtils>(() => new TaxScheduleUtils());

        public static TaxScheduleUtils Instance => instance.Value;

        protected override void Init()
        {
            string sql = @"select a.code + '/' + b.code,a.DescFlexField_PrivateDescSeg1 
                        from CBO_Department a
                        inner join Base_Organization b on a.org = b.ID";

            DataTable dt = sqlUtils.FillSync(sql);

            foreach (DataRow dr in dt.Rows) 
            {
                taxs.Add(dr[0].ToString(), dr[1].ToString());
            }

           
        }
        public override void ReLoad()
        {
            taxs.Clear();
            Init();
        }
        public string GetTaxSchedule(string code, string org)
        {
            if (taxs.ContainsKey($"{code}/{org}"))
                return taxs[$"{code}/{org}"];
            else
                return string.Empty;
        }
    }


}
